package com.example.orderservice.controller;
import com.example.orderservice.module.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/create")
    public String create(){
        String orderID = UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("","orderQueue","订单信息,订单id:"+orderID);
        return "下单成功!";
    }

    @RequestMapping("/create2")
    public String create2(){
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderID(UUID.randomUUID().toString());
        orderInfo.setName("商品"+new Random().nextInt(100));
        rabbitTemplate.convertAndSend("","orderQueue",orderInfo);
        return "下单成功!";
    }
}
